package com.ellricky.market.ui;

import android.content.Intent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.andr.common.util.StrUtil;
import com.ellricky.baselib.BaseConstant;
import com.ellricky.baselib.entity.clue.MyClueDetailEntity;
import com.ellricky.baselib.http.callback.ECallback;
import com.ellricky.baselib.ui.base.BaseDetailActivity;
import com.ellricky.baselib.ui.visit.VisitListActivity;
import com.ellricky.baselib.util.EAppUtil;
import com.ellricky.baselib.widget.DetailItemView;
import com.ellricky.market.R;
import com.flyco.roundview.RoundTextView;

import static com.ellricky.baselib.http.Api.API_CLUE_DETAIL;

public class MarketClueDetailActivity extends BaseDetailActivity {

    private TextView tvNameSex;

    private DetailItemView tvTel;
    private DetailItemView tvAge;
    private DetailItemView tvSchool;
    private DetailItemView tvClueFrom;
    private DetailItemView tvIfReserve;
    private DetailItemView tvClueTime;
    private DetailItemView tvConsultant;

    private RoundTextView btnVisit;

    private FrameLayout flCt;
    private RoundTextView btnChangeCt;

    private String backvisitId = "";
    private String customerId = "";
    private boolean reserve;


    @Override
    public int getContentLayout() {
        return R.layout.my_activity_clue_pool_detail;
    }

    @Override
    public void initUIView() {
        super.initUIView();
        mTvTitle.setText(com.ellricky.baselib.R.string.base_clue_detail);

        tvNameSex = findViewById(com.ellricky.baselib.R.id.tvNameSex);

        tvTel = findViewById(com.ellricky.baselib.R.id.tvTel);
        tvAge = findViewById(com.ellricky.baselib.R.id.tvAge);
        tvSchool = findViewById(com.ellricky.baselib.R.id.tvSchool);
        tvClueFrom = findViewById(com.ellricky.baselib.R.id.tvClueFrom);
//        tvIfReserve = findViewById(com.ellricky.baselib.R.id.tvIfReserve);
//        tvClueTime = findViewById(com.ellricky.baselib.R.id.tvClueTime);
        tvConsultant = findViewById(com.ellricky.baselib.R.id.tvConsultant);


        btnVisit = findViewById(com.ellricky.baselib.R.id.btnVisit);
       /* flCt = findViewById(com.ellricky.baselib.R.id.flCt);
        btnChangeCt = findViewById(com.ellricky.baselib.R.id.btnChangeCt);*/


        btnVisit.setOnClickListener(this);
       /* btnChangeCt.setOnClickListener(this);*/

        loadDetail(id);
    }

    private void loadDetail(String id) {
        mPresenter.loadDetail(API_CLUE_DETAIL, id, new ECallback<MyClueDetailEntity>(this) {
            @Override
            public void onSuccess(MyClueDetailEntity data, String msg) {

                backvisitId = StrUtil.filterEmpty(data.getBackvisitId());
                customerId = StrUtil.filterEmpty(data.getCustomerId());

                tvNameSex.setText(
                        String.format("%s %s", StrUtil.filterEmpty(data.getName()), StrUtil.filterEmpty(data.getSexName()))
                );
                tvTel.setValue(
                        StrUtil.filterEmpty(data.getTel())
                );
                tvAge.setValue(
                        StrUtil.filterEmpty(data.getAgeName())
                );
                tvSchool.setValue(
                        StrUtil.filterEmpty(data.getFromSchool())
                );
                tvClueFrom.setValue(
                        StrUtil.filterEmpty(data.getComeClue())
                );


                reserve = data.hadReserveClass();
                tvIfReserve.setValue(
                        reserve ? "是" : "否"
                );
                tvClueTime.setValue(
                        StrUtil.filterEmpty(data.getClueDate())
                );
                tvConsultant.setValue(
                        StrUtil.filterEmpty(data.getCourseManagerName())
                );
            }
        });
    }

    @Override
    protected void onClickView(View v) {
        super.onClickView(v);
        if (v == btnVisit) {
            EAppUtil.jumpPageWithId(this, VisitListActivity.class, backvisitId);
        } else if (v == btnChangeCt) {
            EAppUtil.jumpSelctCt(this, backvisitId, customerId);
        }

    }




    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == BaseConstant.RESULT_CODE_ADD) {
            // 刷新课程顾问
            loadDetail(id);
        }
    }
}
